﻿using System.Security.Claims;
using Architecture.Api.Application.Command.RoleCommand;
using Architecture.Common;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Architecture.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class RoleController : BaseController
    {
        private readonly IMediator _mediator;

        public RoleController(IMediator mediator)
        {
            _mediator = mediator;
        }

        [HttpPost]
        public async Task<int> Create(RoleCreateCommand command)
        {
            var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var userName = HttpContext.User.FindFirst(ClaimTypes.Name)?.Value;
            var roleName = HttpContext.User.FindFirst(ClaimTypes.Role)?.Value;
            var customerValue = HttpContext.User.FindFirst("CustomClaimType")?.Value;
            var key=HttpContext.User.FindFirst("Key")?.Value;
            command.UserID = userId.ToInt32();
            return await _mediator.Send(command);
        }
    }
}